<template>
  <div class="character-select-view">
    <!-- 背景装饰 -->
    <div class="background-decoration">
      <div class="decoration-circle circle-1"></div>
      <div class="decoration-circle circle-2"></div>
      <div class="decoration-circle circle-3"></div>
    </div>
    
    <div class="container">
      <!-- 页面头部 -->
      <header class="page-header">
        <div class="header-content">
          <router-link to="/" class="back-btn">
            <i class="icon-arrow-left"></i>
            <span>返回</span>
          </router-link>
          <div class="title-section">
            <h1>选择角色</h1>
            <p>每个角色都有独特的能力和特点</p>
          </div>
        </div>
      </header>
      
      <!-- 角色选择组件 -->
      <div class="character-select-container">
        <CharacterSelect @character-selected="handleCharacterSelected" />
      </div>
      
      <!-- 底部提示 -->
      <div class="bottom-hint">
        <div class="hint-item">
          <i class="icon-info"></i>
          <span>解锁更多角色需要完成特定成就</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
import CharacterSelect from '@/components/CharacterSelect.vue'
import type { Character } from '@/game/Character'

/**
 * 角色选择视图组件
 * 提供角色选择页面的布局和导航
 * @component
 */

const router = useRouter()

/**
 * 处理角色选择完成事件
 * @param character - 选择的角色
 */
const handleCharacterSelected = async (character: Character): Promise<void> => {
  console.log('角色选择完成:', character.name)
  
  // 返回主菜单
  await router.push('/')
}
</script>

<style lang="scss" scoped>
@import '@/styles/responsive.scss';

.character-select-view {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 0;
  margin: 0;
  overflow: hidden;
  z-index: 1000;
  
  @include mobile-all {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: -webkit-fill-available;
    padding: env(safe-area-inset-top, 1rem) env(safe-area-inset-right, 1rem) env(safe-area-inset-bottom, 1rem) env(safe-area-inset-left, 1rem);
    margin: 0;
  }

  // 背景装饰
  .background-decoration {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 1;

    .decoration-circle {
      position: absolute;
      border-radius: 50%;
      background: rgba(255, 255, 255, 0.05);
      animation: float 8s ease-in-out infinite;

      &.circle-1 {
        width: 200px;
        height: 200px;
        top: 10%;
        left: -5%;
        animation-delay: 0s;
      }

      &.circle-2 {
        width: 150px;
        height: 150px;
        top: 50%;
        right: -3%;
        animation-delay: 3s;
      }

      &.circle-3 {
        width: 100px;
        height: 100px;
        bottom: 20%;
        left: 15%;
        animation-delay: 6s;
      }
    }
  }

  .container {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 100%;
    max-width: none;
    margin: 0;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    
    @include mobile-all {
      padding: 1rem;
      max-width: none;
      width: 100%;
      height: 100%;
    }
    
    @include mobile-small {
      padding: 0.5rem;
    }
  }

  .page-header {
    margin-bottom: 3rem;
    
    @include mobile-all {
      margin-bottom: 2rem;
    }

    .header-content {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      
      @include mobile-all {
        flex-direction: column;
        gap: 1.5rem;
        text-align: center;
      }

      .back-btn {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.75rem 1.5rem;
        background: rgba(255, 255, 255, 0.15);
        backdrop-filter: blur(10px);
        color: white;
        text-decoration: none;
        border-radius: $border-radius-lg;
        border: 1px solid rgba(255, 255, 255, 0.2);
        transition: all 0.3s ease;
        font-weight: 500;
        
        @include mobile-all {
          align-self: flex-start;
          padding: 0.625rem 1.25rem;
        }
        
        @include touch-device {
          min-height: 44px;
          -webkit-tap-highlight-color: transparent;
          
          &:active {
            background: rgba(255, 255, 255, 0.25);
            transform: scale(0.98);
          }
        }

        @include non-touch-device {
          &:hover {
            background: rgba(255, 255, 255, 0.25);
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
          }
        }

        i {
          font-size: 1.1rem;
        }
      }

      .title-section {
        text-align: right;
        
        @include mobile-all {
          text-align: center;
        }

        h1 {
          color: white;
          font-size: 3rem;
          font-weight: 900;
          margin-bottom: 0.5rem;
          text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.4);
          letter-spacing: -1px;
          
          @include mobile-all {
            font-size: 2.5rem;
          }
          
          @include mobile-small {
            font-size: 2rem;
          }
        }

        p {
          color: rgba(255, 255, 255, 0.9);
          font-size: 1.1rem;
          margin: 0;
          font-weight: 300;
          
          @include mobile-all {
            font-size: 1rem;
          }
          
          @include mobile-small {
            font-size: 0.9rem;
          }
        }
      }
    }
  }

  .character-select-container {
    margin-bottom: 3rem;
    
    @include mobile-all {
      margin-bottom: 2rem;
    }
  }

  .bottom-hint {
    display: flex;
    justify-content: center;
    
    .hint-item {
      display: flex;
      align-items: center;
      gap: 0.75rem;
      background: rgba(255, 255, 255, 0.1);
      backdrop-filter: blur(10px);
      padding: 1rem 1.5rem;
      border-radius: $border-radius-lg;
      color: rgba(255, 255, 255, 0.9);
      border: 1px solid rgba(255, 255, 255, 0.2);
      
      @include mobile-all {
        padding: 0.875rem 1.25rem;
        text-align: center;
      }
      
      @include mobile-small {
        flex-direction: column;
        gap: 0.5rem;
        padding: 1rem;
      }

      i {
        font-size: 1.2rem;
        color: rgba(255, 255, 255, 0.8);
        
        @include mobile-small {
          font-size: 1.5rem;
        }
      }

      span {
        font-size: 0.95rem;
        font-weight: 500;
        
        @include mobile-all {
          font-size: 0.9rem;
        }
        
        @include mobile-small {
          font-size: 0.85rem;
        }
      }
    }
  }

}

// 动画定义
@keyframes float {
  0%, 100% {
    transform: translateY(0px) rotate(0deg);
    opacity: 0.05;
  }
  50% {
    transform: translateY(-20px) rotate(180deg);
    opacity: 0.1;
  }
}

// 图标样式
.icon-arrow-left::before { content: '←'; }
.icon-info::before { content: 'ℹ️'; }

// 响应式设计
@include mobile-all {
  .character-select-view {
    .character-grid {
      grid-template-columns: 1fr;
      gap: 1rem;
      
      @include mobile-medium {
        grid-template-columns: repeat(2, 1fr);
      }
    }
  }
}

@include tablet-all {
  .character-select-view {
    .character-grid {
      grid-template-columns: repeat(2, 1fr);
      gap: 1.5rem;
    }
  }
}

@include desktop-all {
  .character-select-view {
    .character-grid {
      grid-template-columns: repeat(3, 1fr);
      gap: 2rem;
    }
  }
}
</style>